﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// PinchEffect Effect
    /// </summary>
    public class PinchEffect : ShaderEffect
    {
        #region Propriétées de dépendances

        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(PinchEffect), 0);
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(PinchEffect), new UIPropertyMetadata(0.5, ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(PinchEffect), new UIPropertyMetadata(0.5, ShaderEffect.PixelShaderConstantCallback(1)));
        public static readonly DependencyProperty RadiusProperty = DependencyProperty.Register("Radius", typeof(double), typeof(PinchEffect), new UIPropertyMetadata(0.25, ShaderEffect.PixelShaderConstantCallback(2)));
        public static readonly DependencyProperty AmountProperty = DependencyProperty.Register("Amount", typeof(double), typeof(PinchEffect), new UIPropertyMetadata(0.0, ShaderEffect.PixelShaderConstantCallback(3)));

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la propriété Input du Shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(PinchEffect.InputProperty));
            }
            set
            {
                this.SetValue(PinchEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Amount du Shader
        /// </summary>
        public double Amount
        {
            get
            {
                return ((double)this.GetValue(PinchEffect.AmountProperty));
            }
            set
            {
                this.SetValue(PinchEffect.AmountProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété CenterX du Shader
        /// </summary>
        public double CenterX
        {
            get
            {
                return ((double)this.GetValue(PinchEffect.CenterXProperty));
            }
            set
            {
                this.SetValue(PinchEffect.CenterXProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété CenterY du Shader
        /// </summary>
        public double CenterY
        {
            get
            {
                return ((double)this.GetValue(PinchEffect.CenterYProperty));
            }
            set
            {
                this.SetValue(PinchEffect.CenterYProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Radius du Shader
        /// </summary>
        public double Radius
        {
            get
            {
                return ((double)this.GetValue(PinchEffect.RadiusProperty));
            }
            set
            {
                this.SetValue(PinchEffect.RadiusProperty, value);
            }
        }

        #endregion

        #region Variables statiques

        private static readonly PixelShader _PixelShader = new PixelShader();

        #endregion

        #region Constructeurs

        /// <summary>
        /// Constructeur statique
        /// </summary>
        static PinchEffect()
        {
            _PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/Pinch.ps");
        }

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        public PinchEffect()
        {
            this.PixelShader = _PixelShader;

            this.UpdateShaderValue(PinchEffect.InputProperty);
            this.UpdateShaderValue(PinchEffect.CenterXProperty);
            this.UpdateShaderValue(PinchEffect.CenterYProperty);
            this.UpdateShaderValue(PinchEffect.RadiusProperty);
            this.UpdateShaderValue(PinchEffect.AmountProperty);
        }

        #endregion
    }
}
